#include "device.h"

static struct mod_dev_t module_device;

/**
 * @brief 设置模块开关机
 * 
 * @param value 
 * @return int 
 */
int mod_set_power(struct mod_dev_t *dev,uint8_t value)
{
    if(dev==NULL) 
    return -1;
    if(value==1)
    {
        dev->hal_open();
        dev->dev_flag= 1;
    }
    else
    {
        dev->hal_close();
        dev->dev_flag= 0;
    }
	return 0;
}
/**
 * @brief 获取模块状态
 * 
 * @param dev 
 * @return uint8_t 
 */
uint8_t mod_get_device_state(struct mod_dev_t *dev)
{
    return dev->dev_flag;    
}
/**
 * @brief 模块设备控制初始化
 * 
 * @param dev 
 * @return int 
 */
int mod_device_init(struct mod_dev_t **dev)
{
    if(dev==NULL) 
    return -1;
    gpio_ctl_hal_init();
    module_device.hal_open = device_hal_open;
    module_device.hal_close= device_hal_close;
    module_device.set_power= mod_set_power;
    module_device.get_dev_state=mod_get_device_state;
	*dev= &module_device;
	return 0;
}
